package com.itheima.controller;

import com.itheima.domain.SmsCoupon;
import com.itheima.manager.SmsCouponManager;
import com.itheima.util.R;
import com.itheima.vo.SmsCouponVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/coupon")
public class SmsCouponController {

    @Autowired
    SmsCouponManager smsCouponManager;

    //优惠券分页
    @GetMapping("/list")
    public R findByPage(Integer pageNum,Integer pageSize,String name,Integer type){
        return smsCouponManager.findByPage(pageNum,pageSize,name,type);
    }

    //优惠券领取详情
    @GetMapping("/{couponId}")
    public R findById(@PathVariable Long couponId){
        return smsCouponManager.findById(couponId);
    }

    //修改优惠券
    @PostMapping("/update/{id}")
    public R updateById(@PathVariable Long id, @RequestBody SmsCoupon smsCoupon){
        return smsCouponManager.updateById(smsCoupon);
    }

    //删除
    @PostMapping("/delete/{id}")
    public R deleteById(@PathVariable Long id){
        return smsCouponManager.deleteById(id);
    }

    //新增
    @PostMapping("/create")
    public R save(@RequestBody SmsCouponVo smsCouponVo){
        return smsCouponManager.save(smsCouponVo);
    }

}
